<?php
$maxwight = get_shiping_max_weight();
$shipingprice = get_shiping_price();
$priceforunit = get_shiping_price_for_unit();
?>
<div id="mjquery">
    <?php if ($trades) { ?>
        <div class="brands">
            <?php foreach ($trades as $tr) { ?>
                <a href="<?= base_url("products/brands/$tr->id") ?>"><img src="<?= base_url(TRADE_PATH . $tr->image) ?>" alt="" /></a>
            <?php } ?>
        </div>
    <?php } ?>



    <script src="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/js/jquery.bxslider.min.js"></script>
    <link href="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/css/jquery.bxslider.css" rel="stylesheet" />
    <script type="text/javascript">
        $(document).ready(function() {
            $('.bxslider').bxSlider();
        });
    </script>
    <ul class="bxslider">
        <?php if($slider){ ?>
        <?php foreach ($slider as $sl){ ?>
        <li><img style="width: 100%; height: 100%" src="<?= base_url(ADS_PATH.$sl->image) ?>" alt="" /></li>
        <?php } ?>
        <?php }else{ ?>
        <li><img style="width: 100%; height: 100%" src="<?= base_url(ADS_PATH.'sliderdef_'.LANG.'.png') ?>" alt="" /></li>
        <?php } ?>
    </ul>
</div>

<div id="special_offer">
    <form action="<?= base_url('index/mailinglist') ?>" method="post">
        <label><?= lang('label_get_special_offers') ?> : &nbsp;</label>
        <input type="email" name="email" placeholder="<?= lang('label_enter_your_email') ?>" />
        <input type="submit" name="submit" class="soffer_submit" value="" />
    </form>

    <a href="#" class="online"></a>
    <a class="phone"></a>
</div>

<br />


<div id="view_products">
    <div id="sort_tabs">
        <ul class="sort_tabs_a">
            <li><a href="#tspecial_offers"><?= lang('label_special_offers') ?></a></li>
            <li><a href="#tnew_products"><?= lang('label_new_products') ?></a></li>
            <li><a class="lasst" href="#tmost_visited"><?= lang('label_most_visited') ?></a></li>
        </ul>

        <div class="sortby">
            <?= lang('label_sort_by') ?> :
            <select id="mainsortby">
                <option value="new"><?= lang('label_recently_added') ?></option>
                <option value="old"><?= lang('label_old_added') ?></option>
                <option value="price"><?= lang('label_product_price') ?></option>
            </select>
        </div>
    </div>

    <div id="tspecial_offers">
        <div id="category_tabs" class="category_tabs">
            <ul>
                <?php
                $cats = get_main_cats();
                if ($cats) {
                    $index = 1;
                    foreach ($cats as $cat) {
                        $title = unserialize($cat->title);
                        if ($index > 11)
                            break;
                        ?>
                        <li data='cat' class="cat<?= $index ?> <?php if ($index == 10) echo 'lasst' ?>"><a href="#cat<?= $index++ ?>"><?= (isset($title[LANG])) ? $title[LANG] : ((LANG == 'ar') ? $title['en'] : $title['ar']) ?></a></li>
                        <?php
                    }
                }
                ?>
            </ul>

            <?php
            if ($cats) {
                $index = 1;
                foreach ($cats as $cat) {
                    if ($index > 11)
                        break;
                    ?>
                    <div id="cat<?= $index++ ?>">
                        <ul>
                            <?php
                            $products = get_product_from_cat($cat->id, 'special');
                            if ($products) {
                                foreach ($products as $product) {
                                    $images = unserialize($product->images);
                                    $nodef = TRUE;
                                    ?>
                                    <li>
                                        <div>
                                            <a href="<?= base_url('products/view/' . $product->id) ?>">
                                                <img src="<?php
                                                if (count($images) > 0) {
                                                    foreach ($images as $k => $v) {
                                                        if ($v[1] == 'yes') {
                                                            $nodef = false;
                                                            $defimage = $v[0];
                                                            echo base_url(PRODUCT_PATH . $v[0]);
                                                        }
                                                    } if ($nodef) {
                                                        base_url(PRODUCT_PATH . $images[0][0]);
                                                        $defimage = $images[0][0];
                                                    }
                                                } else {
                                                    echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) . '/' . APPPATH . 'views/' . $this->themes->Cms_themes() . '/images/noimage_' . LANG . '.gif';
                                                }
                                                ?>" alt="" ></a>
                                            <span class="price"><b><?= lang('label_rial') ?></b><br /><?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?></span>
                                            <?php if ($product->discount_precentage > 0) { ?>
                                                <span class="stitch"><b> &nbsp;%</b><br /><?= $product->discount_precentage ?></span>
                                            <?php } ?>
                                        </div>
                                        <h4><a href="<?= base_url('products/view/' . $product->id) ?>"><?= $product->name ?></a></h4>
                                        <?php
                                        $size = unserialize($product->size);
                                        if (count($size) > 1) {
                                            ?>
                                            <ul class="size">
                                                <li class="size"><?= lang('label_product_size') ?> : </li>
                                                <?php foreach ($size as $k => $v) { ?>
                                                    <li><?= strtoupper($v) ?></li>
                                                <?php } ?>
                                            </ul>
                                            <?php
                                        } else {
                                            $colors = unserialize($product->colors);
                                            if (count($colors) > 1) {
                                                ?>
                                                <ul class="colors">
                                                    <li class="size"><?= lang('label_product_color') ?> : </li>
                                                    <?php foreach ($colors as $k => $v) { ?>
                                                        <li class="<?= $v ?>"></li>
                                                    <?php } ?>
                                                </ul>
                                            <?php } else { ?>
                                                <ul class="size"><li class="size"></li></ul>
                                                <?php
                                            }
                                        }
                                        ?>
                                        <a class="shipping">: <?php
                                            if ($product->shiping_weghite <= $maxwight) {
                                                echo (double) $shipingprice;
                                            } else {
                                                $weghit = (double) $maxwight - 10;
                                                echo $shipingprice + $priceforunit * $weghit;
                                            }
                                            ?> <?= lang('label_rial') ?></a>
                                        <a class="buynow" href="<?= base_url('products/view/' . $product->id) ?>">&nbsp;</a>
                                        <input type="hidden" id="sortprice" value="<?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?>">
                                        <input type="hidden" id="sortdate" value="<?= $product->create_date; ?>">
                                    </li>
                                    <?php
                                }
                            }
                            ?>

                        </ul>
                    </div>
                    <?php
                }
            }
            ?>

            <div class="white_border"></div>
        </div>
    </div>

    <div id="tnew_products">
        <div id="category_tabs" class="category_tabs">
            <ul>
                <?php
                $cats = get_main_cats();
                if ($cats) {
                    $index = 1;
                    foreach ($cats as $cat) {
                        $title = unserialize($cat->title);
                        if ($index > 11)
                            break;
                        ?>
                        <li data='cat' class="cat<?= $index ?> <?php if ($index == 10) echo 'lasst' ?>"><a href="#cat<?= $index++ ?>"><?= (isset($title[LANG])) ? $title[LANG] : ((LANG == 'ar') ? $title['en'] : $title['ar']) ?></a></li>
                        <?php
                    }
                }
                ?>
            </ul>

            <?php
            if ($cats) {
                $index = 1;
                foreach ($cats as $cat) {
                    if ($index > 11)
                        break;
                    ?>
                    <div id="cat<?= $index++ ?>">
                        <ul>
                            <?php
                            $products = get_product_from_cat($cat->id, 'newest');
                            if ($products) {
                                foreach ($products as $product) {
                                    $images = unserialize($product->images);
                                    $nodef = TRUE;
                                    ?>
                                    <li>
                                        <div>
                                            <img src="<?php
                                            if (count($images) > 0) {
                                                foreach ($images as $k => $v) {
                                                    if ($v[1] == 'yes') {
                                                        $nodef = false;
                                                        $defimage = $v[0];
                                                        echo base_url(PRODUCT_PATH . $v[0]);
                                                    }
                                                } if ($nodef) {
                                                    base_url(PRODUCT_PATH . $images[0][0]);
                                                    $defimage = $images[0][0];
                                                }
                                            } else {
                                                echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) . '/' . APPPATH . 'views/' . $this->themes->Cms_themes() . '/images/noimage_' . LANG . '.gif';
                                            }
                                            ?>" alt="" />
                                            <span class="price"><b><?= lang('label_rial') ?></b><br /><?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?></span>
                                            <?php if ($product->discount_precentage > 0) { ?>
                                                <span class="stitch"><b> &nbsp;%</b><br /><?= $product->discount_precentage ?></span>
                                            <?php } ?>
                                        </div>
                                        <h4><a href="<?= base_url('products/view/' . $product->id) ?>"><?= $product->name ?></a></h4>
                                        <?php
                                        $size = unserialize($product->size);
                                        if (count($size) > 1) {
                                            ?>
                                            <ul class="size">
                                                <li class="size"><?= lang('label_product_size') ?> : </li>
                                                <?php foreach ($size as $k => $v) { ?>
                                                    <li><?= strtoupper($v) ?></li>
                                                <?php } ?>
                                            </ul>
                                            <?php
                                        } else {
                                            $colors = unserialize($product->colors);
                                            if (count($colors) > 1) {
                                                ?>
                                                <ul class="colors">
                                                    <li class="size"><?= lang('label_product_color') ?> : </li>
                                                    <?php foreach ($colors as $k => $v) { ?>
                                                        <li class="<?= $v ?>"></li>
                                                    <?php } ?>
                                                </ul>
                                            <?php } else { ?>
                                                <ul class="size"><li class="size"></li></ul>
                                                <?php
                                            }
                                        }
                                        ?>
                                        <a class="shipping">: <?php
                                            if ($product->shiping_weghite <= $maxwight) {
                                                echo (double) $shipingprice;
                                            } else {
                                                $weghit = (double) $maxwight - 10;
                                                echo $shipingprice + $priceforunit * $weghit;
                                            }
                                            ?> <?= lang('label_rial') ?></a>
                                        <a class="buynow" href="<?= base_url('products/view/' . $product->id) ?>">&nbsp;</a>
                                        <input type="hidden" id="sortprice" value="<?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?>">
                                        <input type="hidden" id="sortdate" value="<?= $product->create_date; ?>">
                                    </li>
                                    <?php
                                }
                            }
                            ?>

                        </ul>
                    </div>
                    <?php
                }
            }
            ?>

            <div class="white_border"></div>
        </div>
    </div>

    <div id="tmost_visited">
        <div id="category_tabs" class="category_tabs">
            <ul>
                <?php
                $cats = get_main_cats();
                if ($cats) {
                    $index = 1;
                    foreach ($cats as $cat) {
                        $title = unserialize($cat->title);
                        if ($index > 11)
                            break;
                        ?>
                        <li data='cat' class="cat<?= $index ?> <?php if ($index == 10) echo 'lasst' ?>"><a href="#cat<?= $index++ ?>"><?= (isset($title[LANG])) ? $title[LANG] : ((LANG == 'ar') ? $title['en'] : $title['ar']) ?></a></li>
                        <?php
                    }
                }
                ?>
            </ul>

            <?php
            $cats = get_main_cats();
            if ($cats) {
                $index = 1;
                foreach ($cats as $cat) {
                    if ($index > 11)
                        break;
                    ?>
                    <div id="cat<?= $index++ ?>">
                        <ul>
                            <?php
                            $products = get_product_from_cat($cat->id, 'visited');
                            if ($products) {
                                foreach ($products as $product) {
                                    $images = unserialize($product->images);
                                    $nodef = TRUE;
                                    ?>
                                    <li data='cat'>
                                        <div>
                                            <img src="<?php
                                            if (count($images) > 0) {
                                                foreach ($images as $k => $v) {
                                                    if ($v[1] == 'yes') {
                                                        $nodef = false;
                                                        $defimage = $v[0];
                                                        echo base_url(PRODUCT_PATH . $v[0]);
                                                    }
                                                } if ($nodef) {
                                                    base_url(PRODUCT_PATH . $images[0][0]);
                                                    $defimage = $images[0][0];
                                                }
                                            } else {
                                                echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) . '/' . APPPATH . 'views/' . $this->themes->Cms_themes() . '/images/noimage_' . LANG . '.gif';
                                            }
                                            ?>" alt="" />
                                            <span class="price"><b><?= lang('label_rial') ?></b><br /><?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?></span>
                                            <?php if ($product->discount_precentage > 0) { ?>
                                                <span class="stitch"><b> &nbsp;%</b><br /><?= $product->discount_precentage ?></span>
                                            <?php } ?>
                                        </div>
                                        <h4><a href="<?= base_url('products/view/' . $product->id) ?>"><?= $product->name ?></a></h4>
                                        <?php
                                        $size = unserialize($product->size);
                                        if (count($size) > 1) {
                                            ?>
                                            <ul class="size">
                                                <li class="size"><?= lang('label_product_size') ?> : </li>
                                                <?php foreach ($size as $k => $v) { ?>
                                                    <li><?= strtoupper($v) ?></li>
                                                <?php } ?>
                                            </ul>
                                            <?php
                                        } else {
                                            $colors = unserialize($product->colors);
                                            if (count($colors) > 1) {
                                                ?>
                                                <ul class="colors">
                                                    <li class="size"><?= lang('label_product_color') ?> : </li>
                                                    <?php foreach ($colors as $k => $v) { ?>
                                                        <li class="<?= $v ?>"></li>
                                                    <?php } ?>
                                                </ul>
                                            <?php } else { ?>
                                                <ul class="size"><li class="size"></li></ul>
                                                <?php
                                            }
                                        }
                                        ?>
                                        <a class="shipping">: <?php
                                            if ($product->shiping_weghite <= $maxwight) {
                                                echo (double) $shipingprice;
                                            } else {
                                                $weghit = (double) $maxwight - 10;
                                                echo $shipingprice + $priceforunit * $weghit;
                                            }
                                            ?> <?= lang('label_rial') ?></a>
                                        <a class="buynow" href="<?= base_url('products/view/' . $product->id) ?>">&nbsp;</a>
                                        <input type="hidden" id="sortprice" value="<?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?>">
                                        <input type="hidden" id="sortdate" value="<?= $product->create_date; ?>">
                                    </li>
                                    <?php
                                }
                            }
                            ?>

                        </ul>
                    </div>
                    <?php
                }
            }
            ?>

            <div class="white_border"></div>
        </div>
    </div>

</div>